package com.xinfan.tank;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @Author xin
 * @Date 2022/5/31 15:46
 * @Version 1.0
 */
public class TankVsTank extends JFrame {
    private TankPanel tankPanel = null;
    private Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {


        new TankVsTank();
    }

    public TankVsTank(){
        System.out.println("1--新游戏    2----继续游戏");
        String key = scanner.next();
        tankPanel = new TankPanel(key);
        new Thread(tankPanel).start();
        this.add(tankPanel);
        this.addKeyListener(tankPanel);
        this.setSize(1300,750);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //监听点击退出事件
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.saveRecord();
                System.exit(0);
            }
        });
    }

}
